package com.anddict;

import com.anddict.sql.DbAdapter;
import com.anddict.R;
import com.anddict.action.TabDatabase;
import com.anddict.action.TabFind;
import com.anddict.util.Reference;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.TabActivity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.widget.TabHost;

public class AndDict extends TabActivity {
	
	private TabDatabase tabDatabase;
	private TabFind tabFind;
	private DbAdapter dbAdapter;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        TabHost mTabHost = getTabHost();
        
        mTabHost.addTab(mTabHost.newTabSpec("tabFind").setIndicator("Find").setContent(R.id.tabFind));
        mTabHost.addTab(mTabHost.newTabSpec("tabDatabase").setIndicator("Database").setContent(R.id.tabDatabase));
        
        // listener for tab
        //mTabHost.setOnTabChangedListener(this);
        
        mTabHost.setCurrentTab(0);
        
        dbAdapter = new DbAdapter();
        tabFind = new TabFind(this, dbAdapter);
        tabDatabase = new TabDatabase(this, dbAdapter);
    }
    
    protected Dialog onCreateDialog(int id) {

    	Log.d(Reference.TAG, "AndCard.onCreateDialog -id " + id);
    	
    	Dialog dialog = null;
    	
      	AlertDialog.Builder builder = new AlertDialog.Builder(this);
       	builder.setMessage(Reference.ALERT_MESSAGES[id]);
       	builder.setCancelable(false);
            
       	builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                 dialog.cancel();
            }
       	});
        // create dialog            
        dialog = builder.create();
        
        return dialog;
    }
    
    // end application
    public void onDestroy(){
    	Log.d(Reference.TAG, "AndCard.onDestroy");
    	super.onDestroy();
    }
}